﻿Shader "Dan/UI/UI_PopArrow"
{
    Properties
    {
        _Color ("Color", Color) = (0.07843138,0.3921569,0.7843137,1)
        _ColorBG ("ColorBG", Color) = (0,0.04054837,0.1254902,1)
        _Emission ("Emission", Float ) = 1
        _Speed ("Speed", Float ) = 0.5
        [Header(Style01)]
        [MaterialToggle] _UseStyle01 ("UseStyle01", Float ) = 0
        _GridDensity ("GridDensity", Float ) = 16
        _ArrowAmount ("ArrowAmount", Float ) = 2
        [MaterialToggle] _UseAlpha ("UseAlpha", Float ) = 1
        [Header(Style02)]
        [MaterialToggle] _UseStyle02 ("UseStyle02", Float ) = 0
        _PosterDensity("PosterDensity", Float ) = 1
        _PosterSteps("PosterSteps",Float)=32
        [MaterialToggle] _UseMask ("UseMask", Float ) = 1

    }
    
    SubShader
    {

        Tags { "IgnoreProjector"="True"
            "Queue"="Transparent"
            "RenderType"="Transparent" }
        LOD 100    
        Blend SrcAlpha OneMinusSrcAlpha
        ZWrite Off 
 
        Pass
        {
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            
            #include "UnityCG.cginc"
            #include "../ShaderLibs/UIFX.cginc"
            #include "../ShaderLibs/UVOperator.cginc"
            struct appdata
            {
                float4 vertex : POSITION;
                float2 uv : TEXCOORD0;
            };
            
            struct v2f
            {
                float4 vertex : SV_POSITION;    
                float2 uv : TEXCOORD0;
                
            };

             float4 _Color;
             float _ArrowAmount;
             float _Speed;
             float _PosterDensity;
            float _PosterSteps;
             float _GridDensity;
             float4 _ColorBG;
             float _Emission;
             float _UseStyle01;
             float _UseStyle02;
             fixed _UseAlpha;
             fixed _UseMask;
            
            v2f vert ( appdata v )
            {
                
                v2f o;
                UNITY_INITIALIZE_OUTPUT(v2f ,o);
                o.vertex = UnityObjectToClipPos(v.vertex);
                
                o.uv = v.uv;        
                return o;
            }
            
            


            fixed4 frag (v2f i ) : SV_Target
            {
                
                
                float2 uv = i.uv;
                //波点箭头
                float2 gridID = floor(uv * _GridDensity) / (_GridDensity - 1);
                float arrow = 1.0 - frac((_ArrowAmount*(gridID.x-abs(gridID.y-0.5))+_Time.y*_Speed));
                float pointMask =UVMaskSpots(uv,_GridDensity,0.8);
                float arrowStyle01 = saturate(arrow*arrow*pointMask);

                //随机箭头
                float ruv = abs(uv.y-0.5);
                float2 rd = float2(floor(frac((_Time.y*_Speed+uv.x-ruv)*_PosterDensity) * _PosterSteps) / (_PosterSteps - 1),0);
                float arrowStyle02 = Flick(rd);
                float alphaVal = saturate(((uv.x+0.5)-ruv))-saturate(((uv.x-0.5)-ruv)*2.0);
                //判断开启
                float useStyle1= lerp( 0, arrowStyle01, _UseStyle01);
                float useAlpha1 = lerp( _UseStyle01,arrowStyle01 , _UseAlpha);
                float useStyle2 =lerp( 0, arrowStyle02, _UseStyle02 )*0.5;
                float useAlpha2 = lerp(  _UseStyle02, alphaVal, _UseMask)*arrowStyle02;
                float arrowStyle = useStyle1+useStyle2;
                //剔除
                clip(useAlpha2+useAlpha1 - 0.5);
               
                

                


                float3 finalColor = lerp(_ColorBG.rgb,_Color.rgb,arrowStyle)*_Emission; 
                return fixed4(finalColor,1);
                
            }
            ENDCG
        }
    }
    
    
    
}
